<?php
include_once 'controller/default.php';
include_once 'connection/connection_database.php';
include_once 'checkForm/xulychuoi.php';

class slider {

    function Insert($slider) {
        $link = "http://".$slider["banner_link"];
        $str = trim(khongdau($slider['slider_title']));
        $subtitle = strtolower(preg_replace('/[^a-z0-9]+/i','',$str)); 
        $sql = "INSERT INTO  banner(banner_url, title, sub_title, banner_link, description, banner_display) VALUES('{$slider["banner_url"]}','{$slider["slider_title"]}', '{$subtitle}', '{$link}', '{$slider["slider_description"]}', '2')";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function Delete($slider) {
        $sql = "DELETE FROM  banner WHERE banner_id='{$slider["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function Update($slider) {
        $link = "http://".$slider["banner_link"];
        $str = trim(khongdau($slider['slider_title']));
        $subtitle = strtolower(preg_replace('/[^a-z0-9]+/i','',$str));
        $sql = "UPDATE  banner SET banner_url='{$slider["banner_url"]}', title='{$slider["slider_title"]}', sub_title='{$subtitle}', banner_link='{$link}', description='{$slider["slider_description"]}' WHERE banner_id='{$slider["id"]}' and banner_display=2";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillAll(){
        $sql = "SELECT * FROM banner WHERE banner_display=2";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function FillOne($slider) {
        $sql = "SELECT * FROM  banner WHERE banner_id='{$slider["id"]}' and banner_display=2";
        $result = mysql_query($sql) or die(mysql_error());
        return mysql_fetch_array($result);
    }

}



?>
